﻿/* 
    Copyright (c) 2010 Microsoft Corporation.  All rights reserved.
    Use of this sample source code is subject to the terms of the Microsoft license 
    agreement under which you licensed this sample source code and is provided AS-IS.
    If you did not accept the terms of the license agreement, you are not authorized 
    to use this sample source code.  For the terms of the license, please see the 
    license agreement between you and Microsoft.
    
*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace NewsReader
{
    public partial class Settings : PhoneApplicationPage
    {
        List<RssProvider> providers;

        public Settings()
        {
            InitializeComponent();
            providers = DataProvider.GetRssProviders();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            textBoxProvider.DataContext = providers.FirstOrDefault(p => p.Code == App.Settings.ProviderSetting) ?? providers.First();
        }

        void doneButton_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        void cancelButton_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        private void textBoxProvider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/RssProviders.xaml", UriKind.Relative));
        }
    }
}